unit ec_callcommonevent;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Buttons,
  StdCtrls, ec_base, comboboxhelper, fpjson, constants;

type

  { TECCallCommonEventFrame }

  TECCallCommonEventFrame = class(TECBaseFrame)
    CommonEventComboBox: TComboBox;
    CommonEventGroupBox: TGroupBox;
  private
    procedure PresetCombobox;
  public
    procedure InitNew; override;
    procedure InitExisting; override;
    procedure MakeResultingCommand; override;
  end;

var
  ECCallCommonEventFrame: TECCallCommonEventFrame;

implementation

{$R *.lfm}

{ TECCallCommonEventFrame }

procedure TECCallCommonEventFrame.PresetCombobox;
begin
  FillDbArrayComboBox(CommonEventComboBox, Db.CommonEvents);
end;

procedure TECCallCommonEventFrame.InitNew;
begin
  PresetCombobox;
  CommonEventComboBox.ItemIndex := 0;
end;

procedure TECCallCommonEventFrame.InitExisting;
var
  Params: TJSONArray;
begin
  PresetCombobox;
  Params := GetFirstParams;
  CommonEventComboBox.ItemIndex := Params.Integers[0] - 1;
end;

procedure TECCallCommonEventFrame.MakeResultingCommand;
begin
  ResultingCommand := SingleLineResultingCommand(
                        COMMON_EVENT_EC_CODE,
                        TJSONArray.Create([
                          CommonEventComboBox.ItemIndex + 1
                        ])
  );
end;

end.

